package com.qfedu.knowledge.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @ClassName LogAspect
 * @Author ykx
 * @Date 2024/1/5 13:05
 * @Version 1.0
 */
@Component
@Aspect
@Slf4j
public class LogAspect {

    @Pointcut("execution(* com.qfedu.knowledge.service.impl.*.*(..))")
    public void pointCut() {
    }

    @Before("pointCut()")
    public void before(JoinPoint jp) throws Throwable {
        // jp.getTarget() 类名
        log.info("执行了" + jp.getTarget() + "类的" + jp.getSignature().getName() + "方法的前置增强");
    }

    @AfterReturning("pointCut()")
    public void after(JoinPoint jp) throws Throwable {
        log.info("执行了" + jp.getTarget() + "类的" + jp.getSignature().getName() + "方法的后置增强");
    }


    @Around("pointCut()")
    public Object around(ProceedingJoinPoint jp) throws Throwable {
        log.info("环绕增强前面处理:连接点类型getKind" + jp.getKind());
        //调用原方法
        Object ob = jp.proceed();
        log.info("环绕增强后面处理:连接点的静态部分getStaticPart" + jp.getStaticPart());
        return ob;
    }


}
